package com.xuecheng.content.controller;

import com.xuecheng.api.content.CourseTeacherApi;
import com.xuecheng.api.content.model.dto.CourseTeacherDTO;
import com.xuecheng.api.content.model.vo.CourseTeacherVo;
import com.xuecheng.common.domain.code.CommonErrorCode;
import com.xuecheng.common.exception.ExceptionCast;
import com.xuecheng.content.common.util.UAASecurityUtil;
import com.xuecheng.content.convert.CourseTeacherConvert;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import com.xuecheng.content.service.CourseTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * <p>
 * 课程-教师关系表 前端控制器
 * </p>
 *
 * @author itcast
 */
@Slf4j
@RestController
@RequestMapping
public class CourseTeacherController implements CourseTeacherApi {

    @Autowired
    private CourseTeacherService courseTeacherService;

    @GetMapping("courseTeacher/list/{courseBaseId}")
    public List<CourseTeacherDTO> queryTeacherList(@PathVariable Long courseBaseId) {

        //获得公司id
        Long companyId = UAASecurityUtil.getCompanyId();
        if (ObjectUtils.isEmpty(companyId)) {
            ExceptionCast.cast(CommonErrorCode.E_100108);
        }
        return courseTeacherService.queryTeacherList(courseBaseId, companyId,false);
    }

    @PostMapping("courseTeacher")
    public CourseTeacherDTO createOrModifyTeacher(@RequestBody CourseTeacherVo vo) {
        //获得公司id
        Long companyId = UAASecurityUtil.getCompanyId();
        //vo-->dto
        CourseTeacherDTO dto = CourseTeacherConvert.INSTANCE.vo2dto(vo);
        return courseTeacherService.createOrModifyTeacher(dto, companyId);
    }

    @DeleteMapping("courseTeacher/course/{courseBaseId}/{courseTeacherId}")
    public void removeTeacher(@PathVariable Long courseBaseId, @PathVariable Long courseTeacherId) {

        //获得公司id
        Long companyId = UAASecurityUtil.getCompanyId();

        courseTeacherService.removeTeacher(courseBaseId, courseTeacherId, companyId);
    }
}
